<?php
/*
 * 品牌制造商
 * @package    auto
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 49b36faf6d53d1fd7f97f5cb2a37fc26eae394b6 $
 */
/**
 * 品牌制造商类
 * Class AutoBrand
 */
class AutoManufactor {

	/*
	 * 获取生产商信息
	 * @param $manufactorId
	 * @return mixed
	 */
	public static function get($manufactorId) {
		global $db;
		$manufactor = array();
		$table      = Table::name(Table::NAME_AUTO_RANK_MANUFACT);
		$RANK       = AutoCategory::getCache(AutoCategory::TYPE_RANK);

		foreach ($RANK as $rank) {
			if ($rank['level'] != 1) {
				continue;
			}
			if ($rank['arid'] == $manufactorId) {
				$manufactor = $rank;
			}
		}
		if (!$manufactor) {
			return $manufactor;
		} else {
			$sql          = "select arid,brand_thumb as thumb, description from $table where arid={$manufactor['arid']}";
			$autoRankManu = $db->getOne($sql);
			if ($autoRankManu) {
				$manufactor   = array_merge($manufactor, $autoRankManu);
			}
			return $manufactor;
		}
	}


	/**
	 * 获取车系列表
	 * @param       $manuid    传入的车系的父ID，即品牌的ID
	 * @return array
	 */
	public static function cars($manuid) {
		global $db;
		$tableAutoCategory = Table::name(Table::NAME_AUTO_CATEGORY);

		$sql = "select * from $tableAutoCategory where parentid = $manuid";
		$cars = $db->getAll($sql);
		return $cars;
	}
}